//
//  RecommendHotelTableCell.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/5/23.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "RecommendHotelTableCell.h"
#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height
#import "RecommendHotelCollectionCell.h"
#import "RecoummendHotelModel.h"

@implementation RecommendHotelTableCell
//自定义初始化
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addView];
//        self.smallArray = [NSMutableArray array];
        
    }
    return self;
}

- (void)addView
{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 20) / 3, 110);
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
//    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 10;
    UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
    
    collectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:collectionV];
    
    //成为代理人
    collectionV.delegate = self;
    collectionV.dataSource = self;
    
    //注册
    [collectionV registerClass:[RecommendHotelCollectionCell class] forCellWithReuseIdentifier:@"reuse"];
    self.myCollectionV = collectionV;
}
//cell数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.myHotelArrayM.count;
}
//建cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommendHotelCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    RecoummendHotelModel *model = [self.myHotelArrayM objectAtIndex:indexPath.row];
    [cell.myImageV sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:nil];
    cell.cnnameLabel.text = model.cnname;
    return cell;
}
- (void)setMyHotelArrayM:(NSArray *)myHotelArrayM
{
    _myHotelArrayM = myHotelArrayM;
    [self.myCollectionV reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myCollectionV.frame = self.contentView.frame;
}

//点击触发方法
//
//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    SubjectModel *model = [self.subjectArray objectAtIndex:indexPath.row + 1];
//    self.myBlock(model.url, model.title);
//}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
